package com.cap.bts.crmdp.dealer.coupon.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.cap.bts.crmdp.dealer.coupon.dao.ICouponBatchLineDao;
import com.cap.bts.crmdp.dealer.coupon.domain.CouponBatchLine;
import com.cap.bts.framework.common.dao.impl.BaseDaoImpl;
import com.cap.bts.framework.common.exception.AppException;

@Repository("couponBatchLineDao")
public class CouponBatchLineDaoImpl extends BaseDaoImpl<CouponBatchLine, Long> implements
                                                                         ICouponBatchLineDao {

    @Inject
    public CouponBatchLineDaoImpl(@Value("com.cap.bts.crmdp.dealer.coupon.domain.CouponBatchLine") Class<CouponBatchLine> clazz) {
        super(clazz);
    }

    /**
     *按活动批次取得优惠券生成列表
     * overridden:
     * @Date        :      Sep 10, 2015
     * @see com.cap.bts.crmdp.dealer.coupon.dao.ICouponBatchLineDao#getCouponBatchLineListByBatchId(java.lang.Long)
    **/
    @Override
    public List<CouponBatchLine> getCouponBatchLineListByBatchId(Long batchId) throws AppException {
        return super.getListByQueryWithVaParam("from CouponBatchLine a where a.couponBatch.id=?1", batchId);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      Sep 10, 2015
     * @see com.cap.bts.crmdp.dealer.coupon.dao.ICouponBatchLineDao#generateCard(java.lang.String)
    **/
    @Override
    public Boolean generateCoupon(String generateInfo) throws AppException {
        super.getEntityManager().createNativeQuery("{ call SSP_COUPON_GENERATION_ADD('"+generateInfo+"')}").executeUpdate();
        return true;
    }

}
